<!doctype html>
<html style="height:100%;">
<head>
<meta charset="utf-8">
<meta content="WangID通城" http-equiv="keywords">
<meta name="description" content="WangID通城">
<meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
<title>WangID通城</title>
<link rel="stylesheet" href="css/index.css" type="text/css">
<link rel="stylesheet" href="css/zy.css" type="text/css">
<link rel="stylesheet" href="css/swiper.min.css" type="text/css">
<script type="text/javascript" src="js/swiper.min.js"></script>
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
	<script src="/js/plugins/jrender/jrender.js"></script>
	<script src="/js/common.js"></script>
</head>
<body style="height: 100%;"> 
<!--页面内容
<div id="yemnr">--> 
<!--头部--> 
<div class="toub_beij toub_beij_zy">
	<div class="zhongj_k zhongj_k_z">
		<div class="jiu_feo">
			<div class="logo_k logo_k_fanh"><a href="javascript:history.go(-1)"><img class="fanh_ann" src="images/web/fanh.png"></a></div>
			<div class="zhongjain_daoh">
				<ul>
					<li><a class="px24">收货地址</a></li>  
				</ul>
			</div>
		</div> 
	</div>
</div>
<script type="text/javascript">
	//滑动头部透明（针对首页头部用）
	window.onscroll=function(){

	var autoheight=document.body.scrollTop||document.documentElement.scrollTop;
	if(autoheight>10){
		$(".toub_beij").css("position" ,"fixed")
		}else{
			$(".toub_beij").css("position" ,"relative")
		}
	}
</script>
<!--内容-->
<div class="shouhdz_hk">
	<div class="shouh_zk" render-loop="list">

		<div class="shouh_dange_beijin">
			<div class="shang">
				<div class="yuanq"><i render-attr="data-id=list.id"></i></div>
				<div class="mz">
					<p><em render-html="list.name"></em> <em render-html="list.tel"></em></p>
					<p render-html="list.detail"></p>
				</div>
			</div>
			<div class="boanjk"><a render-fun="handle" render-key="list.id">编辑</a></div>
		</div>



	</div>
</div> 
<div class="dib_daoh_b">
	<div class="gouwuc_">
		<div class="you">
			<div class="goum">
				<a  class="buyBtn" >确认提交</a>
				<a class="houm addBtn" >新添收货地址</a>
			</div>
		</div>
	</div>
	<!--<div class="gouwuc_ Xinz">
		 <a href="newProductAdd.html">新添收货地址</a>
	</div>-->
</div>

<script>
	$(function () {
        var user = getUser();
        if (user){
        } else {
            window.location.href = "/login.html";
        }

        var userId = user.id;//userId
		var url = getParam();// 拿到url
        if (url) {
            $(".addBtn").attr("href","newProductAdd.html"+url);
        } else {
            $(".addBtn").attr("href","newProductAdd.html");
        }
        // console.log(userId);
        $.get("/users/"+userId+"/addresses" , function (data) {
            // console.log(data);
            $(".shouhdz_hk").renderValues({list:data} , {
			    handle:function (ele, val) {
			        if (url) {
                        ele.href = "/shopping/newProductAdd.html"+url+"&id="+val;
					} else {
                        ele.href = "/shopping/newProductAdd.html?id="+val;
                    }
                }
			});
            $($(".shouhdz_hk i")[0]).addClass("cl");

            $(".shouhdz_hk i").click(function () {
                $(".shouhdz_hk i").removeClass("cl");
                $(this).addClass("cl");
            });
        });

        var goodsId = getParams().goodsId;
        if (goodsId){
        //新增一条购物车信息 userId, goodsId , addressId , state=1
        //扣除积分
        //生成购物信息 //userId && msg ( title  && price )
			$(".buyBtn").click(function () {
				$(".shouhdz_hk i").each(function (i , n) {
					if ($(n).attr("class").indexOf("cl") != -1) {
						var addressId = $(n).data("id");
						$.post("/carts", {userId:userId,goodsId:goodsId,addressId:addressId,state:1},function (data) {

						});

						$.get("/goods/"+goodsId, function (data) {
							$.ajax({
								type:"PUT",
								url:"/users/"+userId+"/points",
								data:{consume:data.price},
								success:function (data) {

								}
							});
							var msg = "兑换1件"+data.title+"成功,花费"+data.price+"积分";
							$.post("/carts/pointmsgs",{userId:userId,msg:msg} , function (data) {

							})

						});

					}
				});
                setTimeout(function () {
                    location.href = "/shopping/record.html";
                },"2000");

			});
        }

        if (getParams().cartId) {
            console.log(getParamss());
            $.each(getParamss() , function (i, n) {
                var cartId = n;
                $(".buyBtn").click(function () {
                    // 更新cart信息 地址 , 时间,状态

						$(".shouhdz_hk i").each(function (i , n) {
							if ($(n).attr("class").indexOf("cl") != -1) {
								var addressId = $(n).data("id");
								$.ajax({
									type:"PUT" ,
									url:"/carts/"+cartId,
									data:{addressId:addressId,state:1},
									success:function (data) {
									}
								});

								// 更新积分
								$.get("/carts/"+cartId, function (data) {
									$.ajax({
										type:"PUT",
										url:"/users/"+userId+"/points",
										data:{consume:data.price},
										success:function (data) {
										}
									});
									//新增一条系统消息
									var msg = "兑换"+data.count+"件"+data.goods.title+"成功,花费"+data.price+"积分";
									$.post("/carts/pointmsgs",{"user.id":userId,msg:msg} , function (data) {
									})
								});
							}
						});
                    setTimeout(function () {
                        location.href = "/shopping/record.html";
                    },"2000");

                });
            })
        }


    })
</script>

</body>
</html>

<!-- <script type="text/javascript">
	window.onload=function(){ 
		var TheMenu=document.getElementById('zhu_caid');
		var LieBiao=document.getElementById('daoh_lb'); 
		var Html=document.getElementsByTagName("html")[0];//0 第一个数组
		TheMenu.onclick=function(event)
		{
			if (LieBiao.style.display=='block')
			{
				LieBiao.style.display='none';
			}
			else {
				LieBiao.style.display='block';
			}  
			event.stopPropagation();//阻止冒泡事件
		} 
		Html.onclick=function(){
			LieBiao.style.display='none';
		}

		// 
		 
 };
 
</script> -->